home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
29
/
applic
/
3dfile.txt
next >
Wrap
Text File
|
1985-11-19
|
7KB
|
199 lines
CAD-3D .3D Object File Format
by Tom Hudson
The CAD-3D solid modeling system uses a fairly straightforward file
format to store user-defined 3-Dimensional objects. Each .3D file can
contain up to 20 objects, but it is suggested that for files that are
intended to be merged with existing groups of objects, the number of
objects should be kept below 10.
File Header
-----------
The first 34 bytes of each .3D file is a header specifying the number
of 3-D objects in the file and direct light source information, as
follows:
Bytes 1-2: A WORD value containing the hex value $3D3D. This is a
"magic number" which may be tested to be sure the file is a 3D object
file.
Bytes 3-4: A WORD value which tells how many 3D objects are contained
in the file. Must range from 1-20. We will refer to this value as
OBCOUNT.
Bytes 5-10: Three WORD values which specify the brightness of the
three direct light sources. These values must range from 0-7. The
first WORD value is the brightness of light source A, the second is the
brightness of light source B, and the third is for light source C.
Bytes 11-16: Three WORD values specifying whether each of the three
light sources are ON or OFF. A value of 0 means the light source is
OFF, a value of 1 means the source is ON. These three words are in
light source A, B, C order, as is all the light source-related
information.
Bytes 17-22: Three WORD values specifying the vertical position of the
light sources A, B and C. A value of 0 indicates the light is from the
TOP, 1 indicates that the light is from the CENTER, and 2 indicates the
light source is from the TOP. Again, these words are in A-B-C order.
Bytes 23-28: Three WORD values specifying the front-back position of
the light sources. 0 indicates the source is positioned at the FRONT,
1 indicates the CENTER, and 2 indicates the BACK position. Also in
source A-B-C order.
Bytes 29-34: Three WORD values specifying the left-right position of
the light sources. 0 indicates the source is to the LEFT, 1 indicates
the source is at the CENTER, 2 indicates the RIGHT position. Also in
source A-B-C order.
3-D Object Data
---------------
The remainder of the file is made up of variable-sized blocks of data
which describe each 3-D object in the file. The OBCOUNT WORD in the
file header tells how many objects are in the file. Read one of these
3-D data blocks for each object in the file.
9 bytes: Object name. This is a simple string of up to eight bytes
plus a terminating $00 byte which is the name of the object as used by
CAD-3D. Names must be unique within the file, and if they are merged
into RAM with objects of the same name, the user must re-enter the
object name. Any characters may be used for this string, but
meaningful names that describe the object, such as CUBE, JET, etc. are
best.
2 bytes: A WORD specifying the number of vertices in the object. May
not exceed 15000. We will refer to this value as VCOUNT.
VCOUNT * 4 bytes: An array of X-coordinate values for the object.
These values must be in the range -45 to +45 for CAD-3D to process
them. In the CAD-3D universe, negative X values are toward the left,
positive X values are toward the right. This is a floating-point array
stored in the Motorola Fast Floating-Point (LIBF) format, in which each
value is four bytes in length. For easiest processing, simply read
this block of data directly into a FLOAT array of sufficient size.
VCOUNT * 4 bytes: An array of Y-coordinate values for the object.
Range from -45 to +45. Negative Y values are toward the front,
positive Y values are toward the back. Like the X coordinate array,
each coordinate is in LIBF format, four bytes per value.
VCOUNT * 4 bytes: An array of Z-coordinate values for the object.
Range from -45 to +45. Negative Z values are toward the bottom,
positive Y values are toward the top of the CAD-3D universe. Also in
LIBF floating-point format.
2 bytes: A WORD specifying the number of faces in the 3-D object. In
CAD-3D, each face is a triangle specified by three vertices, always
given in a counter-clockwise order A-B-C as viewed from the outside of
the object. We will refer to this value as FCOUNT.
The following 8 bytes make up a structure which is repeated FCOUNT
times, one entry for each face.
2 bytes: A WORD specifying the number of vertex A, the first point in
the face. Must be 0<=vertex A<VCOUNT.
2 bytes: A WORD specifying the number of vertex B, the second point of
the face. Must be 0<=vertex B<VCOUNT.
2 bytes: A WORD specifying the number of vertex C, the third point of
the face. Must be 0<=vertex C<VCOUNT.
2 bytes: A WORD specifying the color of the face and whether or not
the line segments of the face are edges.
Bits 0-3: Color of the face. COLOR 1 is 1-7 (where
1 is low brightness and 7 is high brightness),
COLOR 2 is 8-14 (8 is brightness 1, 14 is
brightness 7 for color 2).
Bit 4: Indicates whether or not the line segment from
vertex C to vertex A is an edge. 0=not edge,
1=edge. Used for ALL LINES/EDGES ONLY modes.
Bit 5: Indicates whether or not the line segment from
vertex B to vertex C is an edge.
Bit 6: Indicates whether or not the line segment from
vertex A to vertex B is an edge.
Once the face structure has been read FCOUNT times and processed, you
are ready to begin the process of reading the next 3-D object in the
file, if one exists. If it does, the next information in the file will
be the 9-character name of the next object. If not, you can close the
file.
Final words
-----------
If you have any questions about the CAD-3D file format, please contact
Tom Hudson [76703,4224].
əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə